<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

//后台登陆控制器
class LoginController extends Controller
{
    //登录首页
    public function index(){
        return "login";
        // return view("admin.login");
    }

    //验证码
    public function yzm(){
        //引入验证码类的头文件
        require_once('../resource/code/code.class.php');
    }


    public function login(Request $request){
        $post = $this->validate($request,[
            'username' => 'required',
            'password' => 'required'
        ],[
                'username.required'=>'写个账号吧',
                'password.required'=>'写个密码吧'
            ]);
        //登陆
        $bool = auth()->attempt($post);
        if ($bool){
            //登陆成功
            return "跳转到后台页面";
        }
        return redirect(route('admin.login'))->withErrors(['error'=>'登录失败']);

    }


}
